package com.xxbing.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串工具类
 */
public class StringUtil {

	/**
	 * 验证日期格式
	 */
    public boolean checkDateStyle(String date) {
    	boolean isNum = true; 	
    	String time[] = date.split("-");
    	if(date.equals("") || (date.trim()).equals("")) {
    		System.out.println("输入为空字符");
    		isNum = false;
    	}else if(time.length != 3) {
    		System.out.println("日期长度不符合要求");
    		isNum = false;
    	}else {
    		for (int i = 0; i < time.length; i++) {
				if(!isNumeric(time[i])) {
					System.out.println("输入不是数字");
					isNum = false;
					break;					
				}else {
					if(i==0) {
						if(Integer.parseInt(time[0])>2099 || Integer.parseInt(time[0])<1900){
							System.out.println("输入年份不正确");
							isNum = false;
							break;
						}
					}
					if(i==1) {
						if(Integer.parseInt(time[1])>12 || Integer.parseInt(time[1])<1) {
							System.out.println("输入月份不正确");
							System.out.println(time[1]);
							isNum = false;
							break;
						}
					}
					if(i==2) {
						if(Integer.parseInt(time[2])>31 || Integer.parseInt(time[2])<1) {
							System.out.println("输入日期不正确");
							isNum = false;
							break;
						}
					}
				}
			}
    		
    	}
    	
    	return isNum;
    }
        
    public boolean isNumeric(String str) {  
        Pattern pattern = Pattern.compile("[0-9]*");  
        Matcher isNum = pattern.matcher(str);  
        if (!isNum.matches()) {  
            return false;  
        }  
        return true;  
    }
    

}
